package com.kuaifawu.lwnlawyerclient.Activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.kuaifawu.lwnlawyerclient.LWNNetwork.LWNNetworkCenter;
import com.kuaifawu.lwnlawyerclient.Model.LWNModel_user;
import com.kuaifawu.lwnlawyerclient.R;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONObject;

/**
 * Created by wyk123 on 2015/6/23.
 */
public class LWNWelcomeActivity extends Activity {
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Intent intent=null;

            switch (msg.what){
                case 1:
                    intent=new Intent(LWNWelcomeActivity.this,LWNLoginActivity.class);

                    break;
                case 2:
                    intent=new Intent(LWNWelcomeActivity.this,MainActivity.class);
                    break;
                case 3:
                    intent=new Intent(LWNWelcomeActivity.this,LWNLognWebActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("code","123");
                    intent.putExtras(bundle);
                    break;
            }
            startActivity(intent);
            finish();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
       MobclickAgent.setDebugMode( true );
        MobclickAgent.openActivityDurationTrack(false);
        MobclickAgent.updateOnlineConfig(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        handler.sendEmptyMessageDelayed(2,1000);
        MobclickAgent.onPageStart("SplashScreen");
        MobclickAgent.onResume(this);
    }



    private void getIsWebLogin(){
        LWNNetworkCenter center = LWNNetworkCenter.getInstance();
        String url=center.getIsWebLogn(LWNWelcomeActivity.this);
        HttpUtils httpUtils=center.getUtils();
        httpUtils.send(HttpRequest.HttpMethod.GET,url,new RequestCallBack<Object>() {
            @Override
            public void onSuccess(ResponseInfo<Object> objectResponseInfo) {
                try{
                    JSONObject jsonObject = new JSONObject(objectResponseInfo.result.toString());
                    String string_code = jsonObject.getString("code");
                    String string_msg = jsonObject.getString("msg");
                    switch (String.valueOf(string_code)){
                        case "10000":
                            handler.sendEmptyMessageDelayed(3,1000);

                            break;
                        case "10003":
                            handler.sendEmptyMessageDelayed(1,1000);
                            break;
                        default:
                            handler.sendEmptyMessageDelayed(2,1000);
                            break;
                    }

                } catch (Exception e){
                    e.printStackTrace();
                }

            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });
    }



    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("SplashScreen");
        MobclickAgent.onPause(this);
    }

}
